﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Open_MUD.Kernel.Utils
{
    class Log
    {
        private TextWriter twlog;        
        private static Log __instance = null;
        private static object logLock = new object();

        private String getCurrentData()
        {
            DateTime now = DateTime.Now;
            return now.Year+"_"+now.Month+"_"+now.Day;
        }

        public Log()
        {
            twlog = new StreamWriter( Directory.GetCurrentDirectory() + Config.getInstance().getStringValue("Kernel","datadir") + "\\" + getCurrentData() + "_" + Config.getInstance().getStringValue("Kernel","log") + "");
        }

        public static Log getInstance()
        {
            if (__instance == null)
                __instance = new Log();
            return __instance;
        }

        public void escribir(String msg)
        {
            lock (logLock)
            {
                twlog.WriteLine(msg);
                twlog.Flush();
                Console.WriteLine(msg);
            }
        }

        public void log(String msg)
        {
            escribir( "(" + DateTime.Now +") " + msg);
        }
        
        public void info(String msg)
        {
            escribir("(" + DateTime.Now + ") " + " [INFO] " + msg);            
        }

        public void debug(String msg)
        {
            escribir("(" + DateTime.Now + ") " + msg);
        }
        public void error(String msg)
        {
            escribir("(" + DateTime.Now + ") " + msg);
        }
    }
}
